﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Authorization;
using ARchGL.Platform.Qianbian;
using WebApiClient;
using ARchGL.Platform.Qianbian.InputModels;
using Abp.Events.Bus;
using Newtonsoft.Json;
using Abp.Application.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;
using ARchGL.Platform.Configuration;
using Microsoft.Extensions.Options;
using IdentityModel.Client;
using Newtonsoft.Json.Linq;
using ARchGL.Platform.FileServer;

namespace ARchGL.Platform.Application
{
    /// <summary>
    /// 文件服务 实现
    /// </summary>
    [AbpAuthorize]
    public class SpiderServerAppService : PlatformAppServiceBase
    {
        #region 实例化
        
        private readonly IHttpContextAccessor httpContextAccessor;
        private readonly SpiderConfigOptions spiderConfigOptions;
        private static Dictionary<DateTime, List<QB_QueryProjectAttendanceReportDto>> ProjectAttendanceCache = new Dictionary<DateTime, List<QB_QueryProjectAttendanceReportDto>>();

        public IEventBus EventBus { get; set; }
        public SpiderServerAppService(
            IHttpContextAccessor _httpContextAccessor,
            IOptions<SpiderConfigOptions> _spiderConfigOptions)
        {
            httpContextAccessor = _httpContextAccessor;
            spiderConfigOptions = _spiderConfigOptions.Value;
        }

        #endregion

        /// <summary>
        /// 获取文件服务 Token 信息
        /// </summary>
        /// <returns></returns>
        public async Task<JObject> GetTokenInfo()
        {
            var token = RefreshTokenService.TokenResponse;
            return token?.Json;
        }

        /// <summary>
        /// 只获取 AccessToken
        /// </summary>
        /// <returns></returns>
        public async Task<string> GetAccessToken()
        {
            var token = RefreshTokenService.TokenResponse;
            return token?.AccessToken;
        }
    }
}
